local extension = Package("zishu")
extension.extensionName = "zishu"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["zishu"] = "自书杯",
  ["zishuSP"] = "自书杯",
}

local function AddWinAudio(general)
  local Win = fk.CreateActiveSkill{ name = general.name.."_win_audio" }
  Win.package = extension
  Fk:addSkill(Win)
end

local zishu__mingzhi = fk.CreateVisibilitySkill{
  name = "#tey__mingzhi",
  global = true,
  frequency = Skill.Compulsory,
  card_visible = function(self, player, card)
    if Fk:currentRoom():getCardArea(card) == Card.PlayerHand and
    card:getMark("@@ShownCards-inhand") > 0 then
      return true
    end
  end
}
Fk:addSkill(zishu__mingzhi)

if not Fk.skills["teyvat__cardplace"] then
-- 将一张牌置于一名角色的区域内的通用技能，幽蝶智慧（并非，超级难用），可以根据以下额外数据定制技能：<br>
-- all_choices_exclu，依次为："PlaceEquip"置入装备区（装备牌），"PlaceEquipForce"置入装备区（装备牌，替换原装备），<br>
-- "TrueDelay"置入判定区（真延时），"AsLe"红乐，"AsBing"黑兵，"AsPremeditate"蓄谋，"ToHand"手牌区，<br>
-- 特别地，旧版主服现在只有蓄谋牌，但是没有任何蓄谋的有关的局内效果，蓄谋选项目前只在扶摇服可用（新版本主要需另外适配）<br>
-- only_card，指定的任意张牌，不填默认为玩家区域内的牌，返回id数组 <br>
-- only_target，指定的任意名角色，不填默认为所有角色，返回id数组 <br>
-- expand_pile，如果牌不在角色区域内（如弃牌堆，处理区）需填，返回id数组 <br>
  local teyvat__cardplace = fk.CreateActiveSkill{
    name = "teyvat__cardplace",
    card_num = 1,
    target_num = 1,
    interaction = function(self)
      local all_choices
      if self.all_choices_exclu ~= nil then
        all_choices = self.all_choices_exclu
      else
        all_choices = {"PlaceEquip", "PlaceEquipForce", "TrueDelay", "AsLe", "AsBing", "AsPremeditate", "ToHand"}
      end
      if (not Fk.all_card_types["rfenghou__premeditate"]) then
        table.removeOne(all_choices, "AsPremeditate")
      end
      return UI.ComboBox {choices = all_choices}
    end,
    card_filter = function(self, to_select, selected, player)
      if #selected == 0 and table.contains(self.only_card ~= nil and self.only_card or player:getCardIds("hej"), to_select) then
        local card = Fk:getCardById(to_select, true)
        if self.interaction.data == "PlaceEquip" or self.interaction.data == "PlaceEquipForce" then
          return card.type == Card.TypeEquip
      elseif self.interaction.data == "TrueDelay" then
          return card.sub_type == Card.SubtypeDelayedTrick
      elseif self.interaction.data == "AsLe" then
          return card.color == Card.Red and card.sub_type ~= Card.SubtypeDelayedTrick
      elseif self.interaction.data == "AsBing" then
          return card.color == Card.Black and card.sub_type ~= Card.SubtypeDelayedTrick
      elseif self.interaction.data == "AsPremeditate" or self.interaction.data == "ToHand" then
          return true
        end
      return true
      end
    end,
    target_filter = function(self, to_select, selected, selected_cards, extra_data, player)
      if #selected == 0 and #selected_cards == 1 then
        local card = Fk:getCardById(selected_cards[1], true)
        local target = Fk:currentRoom():getPlayerById(to_select)
        if self.only_target ~= nil and not table.contains(self.only_target, to_select) then 
          return false
        else
          if self.interaction.data == "PlaceEquip" then
            return target:hasEmptyEquipSlot(card.sub_type)
          elseif self.interaction.data == "PlaceEquipForce" then
            return U.canMoveCardIntoEquip(target, selected_cards[1], true)
          elseif self.interaction.data == "TrueDelay" then
            return not target:isProhibited(target, card)
          elseif self.interaction.data == "AsLe" then
            return not target:isProhibited(target, Fk:cloneCard("indulgence"))
          elseif self.interaction.data == "AsBing" then
            return not target:isProhibited(target, Fk:cloneCard("supply_shortage"))
          elseif self.interaction.data == "AsPremeditate" then
            return not table.contains(target.sealedSlots, Player.JudgeSlot)
          elseif self.interaction.data == "ToHand" then
            return true
          end
        return true
        end
      end
    end,
    feasible = function (self, selected, selected_cards)
      return #selected_cards == 1 and #selected == 1
    end,
  }
  Fk:addSkill(teyvat__cardplace)
  Fk:loadTranslationTable{
    ["teyvat__cardplace"] = "放置",
    ["PlaceEquip"] = "（装备）置入装备区空栏",
    ["PlaceEquipForce"] = "（装备）置于装备区并替换原装备",
    ["TrueDelay"] = "（延时锦囊）置入判定区",
    ["AsLe"] = "（红色非延时锦囊）当乐不思蜀使用",
    ["AsBing"] = "（黑色非延时锦囊）当兵粮寸断使用",
    ["AsPremeditate"] = "当蓄谋牌置入判定区",
    ["ToHand"] = "置入手牌区",
  }
end

--武将列表
local lvju = General(extension, "zishu__lvju", "wu", 4, 4, General.Male) 
local bianrang = General(extension, "zishu__bianrang", "qun", 3, 3, General.Male) 
local chendao = General(extension, "zishu__chendao", "shu", 4, 4, General.Male) 
local maohuanghou = General(extension, "zishu__maohuanghou", "wei", 3, 3, General.Female) 
local guli = General(extension, "zishu__guli", "wu", 4, 4, General.Male) 
local SPguli = General(extension, "zishuSP__guli", "wu", 4, 4, General.Male) 
local limi = General(extension, "zishu__limi", "jin", 3, 3, General.Male) 
local mamidi = General(extension, "zishu__mamidi", "han", 3, 3, General.Male) 
mamidi.hidden = true
local liangxi = General(extension, "zishu__liangxi", "wei", 3, 3, General.Male) 
local wangji = General(extension, "zishu__wangji", "wei", 4, 4, General.Male) 
local yongkai = General(extension, "zishu__yongkai", "shu", 4, 4, General.Male) 
local SPyongkai = General(extension, "zishuSP__yongkai", "shu", 4, 4, General.Male)
local yanghong = General(extension, "zishu__yanghong", "shu", 3, 3, General.Male) 
local panzhang = General(extension, "zishu__panzhang", "wu", 4, 4, General.Male) 
local panshu = General(extension, "zishu__panshu", "wu", 3, 3, General.Female) 
local shenpei = General(extension, "zishu__shenpei", "qun", 3, 3, General.Male) 
local duosidawang = General(extension, "zishu__duosidawang", "qun", 4, 4, General.Female)
local shantao = General(extension, "zishu__shantao", "jin", 3, 3, General.Male) 

local zishu__nilang = fk.CreateTriggerSkill{
  name = "zishu__nilang",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    local current = table.find(player.room.alive_players, function(p) return p.phase ~= Player.NotActive end)
    if player:hasSkill(self) and current and target == current then
      return data.card.type == Card.TypeEquip or data.card.trueName == "slash"
    end
  end,
  on_cost = function(self, event, target, player, data)
    if data.card.type == Card.TypeEquip then
      return player.room:askForSkillInvoke(player, self.name, nil, "#zishu__nilang-invoke1")
    elseif data.card.trueName == "slash" then
      return player.room:askForSkillInvoke(player, self.name, nil, "#zishu__nilang-invoke2")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)
    if not player.dead then
      if data.card.type == Card.TypeEquip then
        local use = room:askForUseCard(player, self.name, "slash", "#zishu__nilang1", true, { bypass_distances = true , bypass_times = true })
        if use then
          use.extraUse = true
          room:useCard(use)
        else
          room:loseHp(player, 1, self.name)
        end
      elseif data.card.trueName == "slash" then
        local use = room:askForUseCard(player, self.name, ".|.|.|.|.|equip", "#zishu__nilang2", true, { bypass_distances = true , bypass_times = true })
        if use then
          use.extraUse = true
          room:useCard(use)
        else
          room:loseHp(player, 1, self.name)
        end
      end   
    end
  end,
}
lvju:addSkill(zishu__nilang)
Fk:loadTranslationTable{
  ["zishu__lvju"] = "吕据", 
  ["#zishu__lvju"] = "克绍堂构",
  ["cv:zishu__lvju"] = "老班长与鱼刺",
  ["illustrator:zishu__lvju"] = "真三国大战",
  ["designer:zishu__lvju"] = "环己醇",

  ["zishu__nilang"] = "逆浪",
  [":zishu__nilang"] = "当前回合角色使用【杀】或装备牌后，你可以摸一张牌，然后你选择一项：使用另一种牌（无距离次数限制）；或失去1点体力。",

  ["#zishu__nilang-invoke1"] = "逆浪：是否摸一张牌，若摸牌，你须使用【杀】（无距离次数限制）或失去1点体力。",
  ["#zishu__nilang-invoke2"] = "逆浪：是否摸一张牌，若摸牌，你须使用装备牌或失去1点体力。",
  ["#zishu__nilang1"] = "逆浪：请使用【杀】（无距离次数限制），或失去1点体力。",
  ["#zishu__nilang2"] = "逆浪：请使用装备牌，或失去1点体力。",

  ["$zishu__nilang1"] = "千浪万壑，吾亦逐而踏之！",
  ["$zishu__nilang2"] = "速讨山越草寇，以备北境之患！",
  ["~zishu__lvju"] = "我，耻为叛臣！",
}

local zishu__yanfeng = fk.CreateActiveSkill{
  name = "zishu__yanfeng",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#zishu__yanfeng",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 20 --这技能不会触发特定loop我就**，先加个网杀限制吧，刷起来都不敢想
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and not Fk:currentRoom():getPlayerById(to_select):isNude()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local slashready = {}
    local cards = room:askForCardsChosen(player, target, 1, 1, "he", self.name, "#zishu__yanfeng-discard::"..target.id)
    room:throwCard(cards, self.name, target, player)
    if Fk:getCardById(cards[1]).trueName == "slash" then
    table.insert(slashready, cards[1])
    end
    if player.dead or target.dead then return end
    local slashs = table.filter(room.discard_pile, function (id)
      return Fk:getCardById(id).trueName == "slash"
    end)
    if #slashs == 0 then return end
    local c = room:askForCard(target, 1, 1, false, self.name, false, ".|.|.|^(hand,equip,judge)", "#zishu__yanfeng-use::"..player.id, slashs)
    if #c == 1 then
      room:moveCards({
        ids = c,
        to = target.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonPrey,
        proposer = target.id,
        skillName = self.name,
      })
      table.insertIfNeed(slashready, c[1])
    end
    if #slashready == 2 then
      while not player.dead and not target.dead do
        if #slashready == 0 then break end
        if table.find(slashready, function (id)
          local card = Fk:getCardById(id)
          return target:canUseTo(card, player, {bypass_distances = true, bypass_times = true})
        end) then
          local use = U.askForUseRealCard(room, target, slashready, "slash", self.name, "#zishu__yanfeng-using::"..player.id, {
            bypass_distances = true,
            bypass_times = true,
            extraUse = true,
            expand_pile = slashready,
            must_targets = {player.id},
          }, false, false)
          if use then
            table.removeOne(slashready, use.card.id)
          end
        else
          break
        end
      end
    end
  end,
}

local zishu__furen = fk.CreateTriggerSkill{
  name = "zishu__furen",
  anim_type = "special",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.to == Player.Discard then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:sendLog{
      type = "#PhaseChanged",
      from = player.id,
      arg = Util.PhaseStrMapper(data.to),
      arg2 = "phase_play",
    }
    room:setPlayerMark(player, "@@zishu__furen", 1)
    data.to = Player.Draw
  end,

  refresh_events = {fk.Damaged, fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if player:getMark("@@zishu__furen") > 0 then
      if event == fk.Damaged then
        return target == player
      else
        for _, move in ipairs(data) do
          if move.from == player.id then
            for _, info in ipairs(move.moveInfo) do
              return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip
            end
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@zishu__furen", 0)
  end,
}
local zishu__furen_prohibit = fk.CreateProhibitSkill{
  name = "#zishu__furen_prohibit",
  prohibit_use = function(self, player, card)
    if player:getMark("@@zishu__furen") > 0 then
      return card.trueName ~= "jink"
    end
  end,
}
bianrang:addSkill(zishu__yanfeng)
zishu__furen:addRelatedSkill(zishu__furen_prohibit)
bianrang:addSkill(zishu__furen)

Fk:loadTranslationTable{
  ["zishu__bianrang"] = "边让", 
  ["#zishu__bianrang"] = "尽肃恭乎",
  ["cv:zishu__bianrang"] = "暂无",
  ["illustrator:zishu__bianrang"] = "六龙争霸",
  ["designer:zishu__bianrang"] = "猪",

  ["zishu__yanfeng"] = "言锋",
  [":zishu__yanfeng"] = "出牌阶段，你可以弃置一名其他角色一张牌，令其选择弃牌堆中一张【杀】并获得，若弃置了【杀】且与获得的【杀】不为同一张，其对你使用这两张【杀】。",
  ["zishu__furen"] = "敷衽",
  [":zishu__furen"] = "弃牌阶段，你可以改为执行摸牌阶段；若如此做，你不能使用【闪】以外的牌，直到你受到伤害或失去牌后。",

  ["#zishu__yanfeng"] = "言锋：你可以弃置一名其他角色一张牌，令其获得弃牌堆中一张其选择【杀】并获得，若弃置了【杀】，其对你使用这两张【杀】。",
  ["#zishu__yanfeng-discard"] = "言锋：弃置%dest一张牌，若弃置了【杀】且其后续因此获得了【杀】，其对你使用这两张【杀】。",
  ["#zishu__yanfeng-use"] = "言锋：获得弃牌堆一张【杀】，若%dest弃置了你的【杀】（且与你获得的不为同一张），你对其使用这些【杀】。",
  ["#zishu__yanfeng-using"] = "言锋：对%dest使用你被弃置与获得的【杀】！",
  ["@@zishu__furen"] = "敷衽 禁用非闪",

  ["$zishu__yanfeng1"] = "为了达成目标，力量是必须的。",
  ["$zishu__yanfeng2"] = "为了达成目标，力量是必须的。",
  ["$zishu__furen1"] = "我必须前进，不论有谁阻挡在我面前。",
  ["$zishu__furen2"] = "我必须前进，不论有谁阻挡在我面前。",
  ["~zishu__bianrang"] = "败者…没有借口…",
}

local zishu__shangbing = fk.CreateViewAsSkill{
  name = "zishu__shangbing",
  pattern = ".|.|.|.|.|basic;nullification",
  prompt = "#zishu__shangbing",
  interaction = function(self)
    local all_names = U.getAllCardNames("b")
    table.insert(all_names, "nullification")
    local names = U.getViewAsCardNames(Self, self.name, all_names, Self:getCardIds("h"))
    if #names > 0 then
      return U.CardNameBox { choices = names, all_choices = all_names }
    end
  end,
  card_filter = function(self, to_select, selected)
    return table.contains(Self:getCardIds("h"), to_select) and #selected < (Self:getHandcardNum() - 1)
  end,
  view_as = function(self, cards)
    if not self.interaction.data or #cards ~= (Self:getHandcardNum() - 1) then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    card:addSubcards(cards)
    return card
  end,
  before_use = function (self, player, use)
    player.room:setPlayerMark(player, "zishu__shangbing_name", use.card.trueName)
    player.room:setPlayerMark(player, "zishu__shangbing_num", #use.card.subcards)
    local record = {player:getMark("zishu__shangbing_name"), player:getMark("zishu__shangbing_num")}
    player.room:setPlayerMark(player, "@zishu__shangbing", record)
  end,
  enabled_at_play = function (self, player)
    return #player.player_cards[Player.Hand] > 1
  end,
  enabled_at_response = function (self, player, response)
    return #player.player_cards[Player.Hand] > 1
  end,
}
local zishu__shangbing_trigger = fk.CreateTriggerSkill{
  name = "#zishu__shangbing_trigger",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or not player:isKongcheng() then return end
    for _, move in ipairs(data) do
      if #move.moveInfo == 1 and move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand then
            return player:getMark("zishu__shangbing_num") > 0 and player:getMark("zishu__shangbing_name") ~= 0 and
            Fk:getCardById(info.cardId, true).trueName == player:getMark("zishu__shangbing_name")
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local cards = {}
    for _, move in ipairs(data) do -- 可能会有陈到手牌打包到其他牌里面一起弃置的问题，需要单独摘出来展示
      if #move.moveInfo == 1 and move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand and Fk:getCardById(info.cardId, true).trueName == player:getMark("zishu__shangbing_name") then
            table.insert(cards, info.cardId)
          end
        end
      end
    end
    if #cards == 1 then
      for _, id in ipairs(cards) do
      player:showCards(Fk:getCardById(id, true))
      end
    end
    player:drawCards(player:getMark("zishu__shangbing_num"), self.name)
  end,
}
zishu__shangbing:addRelatedSkill(zishu__shangbing_trigger)
chendao:addSkill(zishu__shangbing)
Fk:loadTranslationTable{
  ["zishu__chendao"] = "陈到", 
  ["#zishu__chendao"] = "上兵鸿烈",
  ["cv:zishu__chendao"] = "暂无",
  ["illustrator:zishu__chendao"] = "Thinking",
  ["designer:zishu__chendao"] = "环己醇",

  ["zishu__shangbing"] = "上兵",
  [":zishu__shangbing"] = "你可以选择一张手牌并将其余手牌当任意基本牌或【无懈可击】使用或打出；你失去唯一手牌时展示之，"..
  "若与你上次因“上兵”使用或打出的牌同名，你摸X张牌(X为你上次因“上兵”转化的牌数)。<a href='zishu__shangbing_href'>注释</a>",
  ["zishu__shangbing_href"] = "上兵选牌的方式为：若你的手牌数大于1，你选择手牌数减一张手牌，将这些牌当需要的牌使用或打出。",

  ["#zishu__shangbing"] = "上兵：你可以选择任意张手牌当任意基本牌或【无懈可击】使用或打出（需仅剩一张手牌）",
  ["@zishu__shangbing"] = "上兵",
  ["#zishu__shangbing_trigger"] = "上兵",

  ["$zishu__shangbing1"] = "为了达成目标，力量是必须的。",
  ["$zishu__shangbing2"] = "我必须前进，不论有谁阻挡在我面前。",
  ["~zishu__chendao"] = "败者…没有借口…",
}

local zishu__zhaoxi = fk.CreateTriggerSkill{
  name = "zishu__zhaoxi",
  events = {fk.Damaged, fk.HpRecover},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    local logic = player.room.logic
    if event == fk.Damaged then
    local damage_event = logic:getCurrentEvent():findParent(GameEvent.Damage, true)
    if damage_event == nil then return false end
      local events = logic.event_recorder[GameEvent.Damage] or Util.DummyTable
      local last_find = false
      for i = #events, 1, -1 do
        local e = events[i]
        if e.id == damage_event.id then
          last_find = true
        elseif last_find then
          local last_damage = e.data[1]
          if player == target then
            if last_damage.to ~= player then
              self.cost_data = last_damage.to
              player.room:setPlayerMark(player, "@zishu__zhaoxi1", self.cost_data.general)
              return true
            end
          else
            player.room:setPlayerMark(player, "@zishu__zhaoxi1", player.general)
            return false
          end
          return false
        end
      end
    elseif event == fk.HpRecover then
      local recover_event = logic:getCurrentEvent():findParent(GameEvent.Recover, true)
      if recover_event == nil then return false end
        local events = logic.event_recorder[GameEvent.Recover] or Util.DummyTable
        local last_find = false
        for i = #events, 1, -1 do
          local e = events[i]
          if e.id == recover_event.id then
            last_find = true
          elseif last_find then
            local last_recover = e.data[1]
            if player ~= target then
              if last_recover.who == player then
                self.cost_data = target
                player.room:setPlayerMark(player, "@zishu__zhaoxi2", target.general)
                return true
              end
            else
              player.room:setPlayerMark(player, "@zishu__zhaoxi2", player.general)
              return false
            end
            return false
          end
        end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.Damaged then
    return player.room:askForSkillInvoke(player, self.name, nil, "#zishu__zhaoxi-invoke1")
  elseif event == fk.HpRecover then
    return player.room:askForSkillInvoke(player, self.name, nil, "#zishu__zhaoxi-invoke2")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      room:recover({
        who = self.cost_data,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      })
    elseif event == fk.HpRecover then
      player:drawCards(1, self.name)
      if not self.cost_data.dead then
      self.cost_data:drawCards(1, self.name)
      end
    end
  end,
}

local zishu__lengluo = fk.CreateActiveSkill{
  name = "zishu__lengluo",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#zishu__lengluo",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    U.swapHandCards(room, player, player, target, self.name)
    room:setPlayerMark(player, "zishu__lengluo", target.id)
    room:setPlayerMark(player, "@zishu__lengluo", target.general)
    U.askForUseVirtualCard(player.room, target, "ice__slash", nil, self.name, nil, true, true, true, true, {
      extraUse = true,
      must_targets = {player.id},
    }, false)
  end,
}
local zishu__lengluo_delay = fk.CreateTriggerSkill{
  name = "#zishu__lengluo_delay",
  events = {fk.Damaged},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:getMark("zishu__lengluo") ~= 0 then
      local p = player.room:getPlayerById(player:getMark("zishu__lengluo"))
      if p then
        return true
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local p = player.room:getPlayerById(player:getMark("zishu__lengluo"))
    if p then
      room:setPlayerMark(player, "zishu__lengluo", 0)
      room:setPlayerMark(player, "@zishu__lengluo", 0)
      U.swapHandCards(room, player, player, p, self.name)
    end
  end,
}
maohuanghou:addSkill(zishu__zhaoxi)
zishu__lengluo:addRelatedSkill(zishu__lengluo_delay)
maohuanghou:addSkill(zishu__lengluo)

Fk:loadTranslationTable{
  ["zishu__maohuanghou"] = "毛皇后", 
  ["#zishu__maohuanghou"] = "宫风秋毫",
  ["cv:zishu__maohuanghou"] = "暂无",
  ["illustrator:zishu__maohuanghou"] = "醉染浮生",
  ["designer:zishu__maohuanghou"] = "猪",

  ["zishu__zhaoxi"] = "朝夕",
  [":zishu__zhaoxi"] = "你受到伤害后，若上名受到伤害的角色不为你，你可以令其回复1点体力。其他角色回复体力后，若上名回复体力的角色为你，你可以与其各摸一张牌。",
  ["zishu__lengluo"] = "冷落",
  [":zishu__lengluo"] = "出牌阶段限一次，你可以与一名角色交换手牌至你受到伤害后，然后其可以视为对你使用冰【杀】。<a href='zishu__lengluo_href'>（标准描述）</a>",
  ["zishu__lengluo_href"] = "出牌阶段限一次，你可以与一名其他角色交换手牌并记录其（覆盖已有），然后其可以视为对你使用冰【杀】。你受到伤害后，与你本技能记录的角色交换手牌并清除记录。",

  ["@zishu__zhaoxi1"] = "上受",
  ["@zishu__zhaoxi2"] = "本回",
  ["#zishu__zhaoxi-invoke1"] = "朝夕：是否令上名受伤角色回复1点体力？",
  ["#zishu__zhaoxi-invoke2"] = "朝夕：是否与本次回复角色各摸一张牌？",
  ["#zishu__lengluo"] = "你可以与一名角色交换手牌至你受到伤害后，然后其可以视为对你使用冰【杀】。",
  ["@zishu__lengluo"] = "冷落",
  ["#zishu__lengluo_delay"] = "冷落",

  ["$zishu__zhaoxi1"] = "为了达成目标，力量是必须的。",
  ["$zishu__zhaoxi2"] = "我必须前进，不论有谁阻挡在我面前。",
  ["$zishu__lengluo1"] = "为了达成目标，力量是必须的。",
  ["$zishu__lengluo2"] = "我必须前进，不论有谁阻挡在我面前。",
  ["~zishu__maohuanghou"] = "败者…没有借口…",
}
local zishu__weilan_active = fk.CreateActiveSkill{
  name = "zishu__weilan_active",
  card_num = 1,
  target_num = 1,
  card_filter = function(self, to_select, selected)
    return table.contains(Self:getCardIds("he"), to_select)
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
}
Fk:addSkill(zishu__weilan_active)
local zishu__weilan = fk.CreateTriggerSkill{
  name = "zishu__weilan",
  anim_type = "offensive",
  events = {fk.RoundStart},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if player:hasSkill(self) then --要么有牌可挪，要么有牌可分（还要考虑十常侍退场，不能只检测有牌）
      return table.find(room.alive_players, function(p) 
        for _, id in ipairs(room:getOtherPlayers(p)) do return p:canMoveCardsInBoardTo(id) end end) or 
        (table.find(room:getOtherPlayers(player), function(p) return p ~= player end) and not player:isNude())
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choices = { "Cancel" }
    if table.find(room.alive_players, function(p) 
      for _, id in ipairs(room:getOtherPlayers(p)) do return p:canMoveCardsInBoardTo(id) end end) then
      table.insert(choices, "MoveCardsInBoard")
    end
    if table.find(room:getOtherPlayers(player), function(p) return p ~= player end) and not player:isNude() then
      table.insert(choices, "GiveCardsOut")
    end
    if #choices < 2 then return end
    local choice = room:askForChoice(player, choices, self.name, "#zishu__weilan-choice")
    if choice ~= "Cancel" then
      self.cost_data = choice
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("zishu__weilan-round")
    if self.cost_data == "MoveCardsInBoard" then
      local targets = room:askForChooseToMoveCardInBoard(player, "#zishu__weilan-move", self.name, false)
      if #targets ~= 0 then
        room:askForMoveCardInBoard(player, room:getPlayerById(targets[1]), room:getPlayerById(targets[2]), self.name)
        table.insertIfNeed(mark, targets[1])
        table.insertIfNeed(mark, targets[2])
        room:setPlayerMark(player, "zishu__weilan-round", #mark > 0 and mark or 0)
      end
    elseif self.cost_data == "GiveCardsOut" then
    local _, dat = room:askForUseActiveSkill(player, "zishu__weilan_active", "#zishu__weilan_active", false, nil)
    if dat then
      room:moveCardTo(dat.cards, Player.Hand, room:getPlayerById(dat.targets[1]), fk.ReasonGive, self.name, nil, true, player.id)
      table.insertIfNeed(mark, player.id)
      table.insertIfNeed(mark, dat.targets[1])
    end
      room:setPlayerMark(player, "zishu__weilan-round", #mark > 0 and mark or 0)
    end
  end,
}
local zishu__weilan_delay = fk.CreateTriggerSkill{
  name = "#zishu__weilan_delay",
  events = {fk.Damaged},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    local mark = player:getTableMark("zishu__weilan-round")
    if #mark ~= 0 and table.contains(mark, target.id) then
      return true
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@zishu__weilan-round", 1)
    local x = player:getMark("@zishu__weilan-round")
    local choices = {"#zishu__weilan-draw:::"..x , "Cancel"}
    local choice = room:askForChoice(target, choices, self.name, "#zishu__weilan_delay-choice")
    if choice == "#zishu__weilan-draw:::"..x then
      room:setPlayerMark(player, "@zishu__weilan-round", 0)
      room:setPlayerMark(player, "zishu__weilan-round", 0)
      target:drawCards(x, zishu__weilan.name)
    end
  end,
}
local zishu__jibian = fk.CreateViewAsSkill{
  name = "zishu__jibian",
  anim_type = "offensive",
  pattern = "slash",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local c = Fk:cloneCard("slash")
    c.skillName = self.name
    return c
  end,
  before_use = function(self, player, use)
    use.extraUse = true
    if #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
      return e.data[1].from == player.id
    end, Player.HistoryTurn) == 0 then
    use.extra_data = use.extra_data or {}
    use.extra_data.zishu__jibian = player.id
    end
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryTurn) < 1
  end,
  enabled_at_response = function(self, player, res)
    return not res and player:usedSkillTimes(self.name, Player.HistoryTurn) < 1
  end,
}
local zishu__jibian_trigger = fk.CreateTriggerSkill{
  name = "#zishu__jibian_trigger",
  mute = true,
  events = { fk.AskForCardUse, fk.CardUseFinished }, --原汤化原食，犀嬉可往，我亦可往
  can_trigger = function (self, event, target, player, data)
  if event == fk.AskForCardUse then
    if target ~= player then return end
    if data.cardName == "jink" then
      local effect = data.eventData
      return effect and effect.card and table.contains(effect.card.skillNames, zishu__jibian.name)
      and effect.card.trueName == "slash"
      -- 犀嬉限制只有自己和最初的目标才能特殊响应……但是这个描述是目标，也就是都可以这么干
      -- 这个写法不知道能不能防止慕容评变出其不意之后还可以用闪抵消，待验证
    end
  else
    return target == player and data.card.trueName == "slash" and table.contains(data.card.skillNames, zishu__jibian.name)
    and data.extra_data and data.extra_data.zishu__jibian == player.id
  end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
  if event == fk.AskForCardUse then
    local card = room:askForCard(target, 1, 1, true, zishu__jibian.name, true, ".|.|.|.|.|defensive_ride,offensive_ride", "#zishu__jibian_use")
    if #card > 0 then
      data.result = {
        from = target.id,
        card = Fk:cloneCard('jink'),
      }
      data.result.card.skillName = zishu__jibian.name
      data.result.card:addSubcard(card[1])

      if data.eventData then
        data.result.toCard = data.eventData.toCard
        data.result.responseToEvent = data.eventData.responseToEvent
      end

    return true
    end
  elseif event == fk.CardUseFinished then
    for _, id in ipairs(TargetGroup:getRealTargets(data.tos)) do
      local p = player.room:getPlayerById(id)
      if p:isWounded() then
        room:recover({
          who = p,
          num = 1,
          recoverBy = player,
          skillName = zishu__jibian.name,
        })
      end
    end
    end
  end,
}
local zishu__jibian_targetmod = fk.CreateTargetModSkill{
  name = "#zishu__jibian_targetmod",
  bypass_times = function(self, player, skill, scope, card)
    return card and scope == Player.HistoryPhase and table.contains(card.skillNames, zishu__jibian.name)
  end,
}
zishu__weilan:addRelatedSkill(zishu__weilan_delay)
guli:addSkill(zishu__weilan)
zishu__jibian:addRelatedSkill(zishu__jibian_targetmod)
zishu__jibian:addRelatedSkill(zishu__jibian_trigger)
guli:addSkill(zishu__jibian)
Fk:loadTranslationTable{
  ["zishu__guli"] = "谷利", 
  ["#zishu__guli"] = "争舵快航",
  ["cv:zishu__guli"] = "暂无",
  ["illustrator:zishu__guli"] = "YanBai",
  ["designer:zishu__guli"] = "yyuaN",

  ["zishu__weilan"] = "卫澜",
  [":zishu__weilan"] = "每轮开始时，你可以移动场上或分配你的一张牌。每轮限一次，本轮因此获得或失去牌的角色受到伤害后，其可以摸X张牌。(X为这两名角色本轮受伤次数之和)。",
  ["zishu__jibian"] = "急鞭",
  [":zishu__jibian"] = "每回合限一次，你可以视为使用无次数限制的【杀】且目标可以将坐骑牌当【闪】使用，若为你本回合使用的首张牌，结算后令目标回复1点体力。",

  ["GiveCardsOut"] = "分配牌",
  ["MoveCardsInBoard"] = "移动场上牌",
  ["#zishu__weilan_active"] = "卫澜：请将一张牌交给一名其他角色！",
  ["zishu__weilan_active"] = "卫澜",
  ["#zishu__weilan-choice"] = "卫澜：请选择需要的移牌操作",
  ["#zishu__weilan-move"] = "卫澜：请移动场上一张牌",
  ["@zishu__weilan-round"] = "卫澜",
  ["#zishu__weilan_delay"] = "卫澜",
  ["#zishu__weilan_delay-choice"] = "卫澜：是否触发每轮限一次的摸牌？",
  ["#zishu__weilan-draw"] = "摸%arg张牌",
  ["#zishu__jibian_trigger"] = "急鞭",
  ["#zishu__jibian_use"] = "急鞭：是否将一张坐骑牌当【闪】使用响应此【杀】？",

  ["$zishu__weilan1"] = "为了达成目标，力量是必须的。",
  ["$zishu__weilan2"] = "我必须前进，不论有谁阻挡在我面前。",
  ["$zishu__jibian1"] = "为了达成目标，力量是必须的。",
  ["$zishu__jibian2"] = "我必须前进，不论有谁阻挡在我面前。",
  ["~zishu__guli"] = "败者…没有借口…",
}

local zishu__jingfan = fk.CreateTriggerSkill{
  name = "zishu__jingfan",
  dynamic_desc = function(self, player)
    local mark = player:getMark("@@zishu__jingfan")
    if mark > 0 then
    return "锁定技，（一名角色）的准备阶段，若你有红色牌，你重铸至少一张红色牌，"..
      "否则你展示手牌，令当前回合角色摸三张牌，复原本技能。"
    end
  end,
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    local mark = player:getMark("@@zishu__jingfan")
    return (mark > 0 or target == player) and player:hasSkill(self) and target.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local draw = true
    if #table.filter(player:getCardIds("he"), function(id) return Fk:getCardById(id).color == Card.Red end) > 0 then
      draw = false
    end
    if draw then
      if not player:isKongcheng() then
        player:showCards(player.player_cards[player.Hand])
      end
      if not target.dead then
      target:drawCards(3, self.name)
      end
      room:setPlayerMark(player, "@@zishu__jingfan", 0)
    else
    local bas = room:askForCard(player, 1, 999, true, self.name, false, ".|.|heart,diamond", "#zishu__jingfan-recast")
    room:recastCard(bas, player, self.name)
    room:setPlayerMark(player, "@@zishu__jingfan", 1)
    end
  end,

  on_lose = function (self, player, is_death)
    local room = player.room
    room:setPlayerMark(player, "@@zishu__jingfan", 0)
  end,
}

SPguli:addSkill(zishu__jingfan)
Fk:loadTranslationTable{
  ["zishuSP__guli"] = "谷利", 
  ["#zishuSP__guli"] = "争舵快航",
  ["cv:zishuSP__guli"] = "暂无",
  ["illustrator:zishuSP__guli"] = "未知",
  ["designer:zishuSP__guli"] = "猪",

  ["zishu__jingfan"] = "惊帆",
  [":zishu__jingfan"] = "锁定技，（你）的准备阶段，若你有红色牌，你重铸至少一张红色牌，将（）的描述改为“一名角色”；否则你展示手牌，令当前回合角色摸三张牌，复原本技能。",

  ["@@zishu__jingfan"] = "惊帆 皆发",
  ["#zishu__jingfan-recast"] = "惊帆：重铸至少一张红色牌，且其他角色的准备阶段你也将触发本技能！",

  ["$zishu__jingfan1"] = "为了达成目标，力量是必须的。",
  ["$zishu__jingfan2"] = "我必须前进，不论有谁阻挡在我面前。",
  ["~zishuSP__guli"] = "败者…没有借口…",
}
local zishu__shuli = fk.CreateActiveSkill{
  name = "zishu__shuli",
  anim_type = "control",
  card_num = 0,
  target_num = 0,
  --prompt = "#zishu__shuli",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local suits = {}
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|club",
    }
    room:judge(judge)
    table.insertIfNeed(suits, judge.card.suit)
    if judge.card.suit == Card.Club then
      player:drawCards(1, self.name)
    end
    local targets = table.filter(room:getOtherPlayers(player, false), function(p) return player:canPindian(p) end)
    if #targets > 0 then
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#zishu__shuli-choose", self.name, false)
      if #tos > 0 then
        local to = room:getPlayerById(tos[1])
        local pindian = player:pindian({to}, self.name)
        table.insertIfNeed(suits, pindian.fromCard.suit)
        table.insertIfNeed(suits, pindian.results[tos[1]].toCard.suit)
        if #suits == 3 then
          player:drawCards(1, self.name)
        end
        if pindian.results[to.id].winner == player and not player.dead then
          player:drawCards(1, self.name)
        end
      end
    end
  end,
}
local zishu__lunqing = fk.CreateViewAsSkill{
  name = "zishu__lunqing",
  pattern = "peach",
  card_filter = function(self, to_select, selected)
    return #selected < 4
  end,
  view_as = function(self, cards)
    if #cards ~= 4 then return end
    local c = Fk:cloneCard("peach")
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
}
local zishu__lunqing_trigger = fk.CreateTriggerSkill{
  name = "#zishu__lunqing_trigger",
  anim_type = "drawcard",
  events = { fk.CardUsing },
  can_trigger = function(self, event, target, player, data)
    return target == player and data.card.trueName == "peach" and data.card.skillName == "zishu__lunqing" and player:isKongcheng()
    and #data.card.subcards == 4
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local suits = {}
    for _, id in ipairs(data.card.subcards) do
      table.insertIfNeed(suits, Fk:getCardById(id).suit)
    end
    player:drawCards(#suits, zishu__lunqing.name)
  end,
}
zishu__lunqing:addRelatedSkill(zishu__lunqing_trigger)
limi:addSkill(zishu__shuli)
limi:addSkill(zishu__lunqing)
Fk:loadTranslationTable{
  ["zishu__limi"] = "李密", 
  ["#zishu__limi"] = "青心难切",
  ["cv:zishu__limi"] = "暂无",
  ["illustrator:zishu__limi"] = "未知",
  ["designer:zishu__limi"] = "猪",

  ["zishu__shuli"] = "述理",
  [":zishu__shuli"] = "出牌阶段限一次，你可以进行一次判定，然后进行一次拼点：若判定与拼点的共计三张牌花色各不同，你摸一张牌；若判定结果为♣，你摸一张牌；若你拼点且赢，你摸一张牌。",
  ["zishu__lunqing"] = "论情",
  [":zishu__lunqing"] = "你可以将四张牌当 《空巢：摸转化花色数张牌》 的【桃】使用。<a href='zishu__lunqing_href'>（标准描述）</a>",
  ["zishu__lunqing_href"] = "你可以将四张牌当【桃】使用，使用时若你没有手牌，你摸转化花色数张牌。",

  ["#zishu__shuli-choose"] = "述理：请与一名角色拼点！",
  ["#zishu__lunqing_trigger"] = "论情",

  ["$zishu__shuli1"] = "为了达成目标，力量是必须的。",
  ["$zishu__shuli2"] = "我必须前进，不论有谁阻挡在我面前。",
  ["$zishu__lunqing1"] = "为了达成目标，力量是必须的。",
  ["$zishu__lunqing2"] = "我必须前进，不论有谁阻挡在我面前。",
  ["~zishu__limi"] = "败者…没有借口…",
}

Fk:loadTranslationTable{
  ["zishu__mamidi"] = "马日磾", 
  ["#zishu__mamidi"] = "折槛焚裘",
  ["cv:zishu__mamidi"] = "暂无",
  ["illustrator:zishu__mamidi"] = "猎枭",
  ["designer:zishu__mamidi"] = "森博十夜",

  ["zishu__chongtian"] = "崇天",
  [":zishu__chongtian"] = "有角色拼点时，你可以重铸一张牌，将拼点各方的拼点牌点数各改为13-X，X为其拼点牌与你重铸牌点数差的绝对值。",
  ["zishu__shibian"] = "势辩",
  [":zishu__shibian"] = "有角色需要使用【杀】/【闪】时，其可以与上名使用此牌且不为其的角色拼点，若其赢则视为使用之；若赢者不为你或一号位，赢者失去1点体力，并将描述中“一号位”所指代的角色改为本次赢者。",

  ["$zishu__chongtian"] = "为了达成目标，力量是必须的。",
  ["$zishu__shibian"] = "我必须前进，不论有谁阻挡在我面前。",
  ["~zishu__mamidi"] = "败者…没有借口…",
}

local zishu__yuanjiang = fk.CreateTriggerSkill{
  name = "zishu__yuanjiang",
  anim_type = "drawcard",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local x = player:getMark("@zishu__yuanjiang-phase")
      if x == 0 then return false end
      if type(x) == "string" then x = 0 end
      return x > player:getHandcardNum()
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(1)
    room:moveCards({
      ids = cards,
      toArea = Card.Processing,
      moveReason = fk.ReasonPut,
      skillName = self.name,
      proposer = player.id
    })
    if #cards > 0 then
      local current = table.find(room.alive_players, function(p) return p.phase ~= Player.NotActive end)
      if not current and not player.dead then
        room:obtainCard(player, cards, true, fk.ReasonJustMove, player.id, self.name)
      elseif current and not player.dead then
        local use = U.askForUseRealCard(room, current, cards, nil, self.name,
        "#zishu__yuanjiang-use::"..player.id,
        {
          expand_pile = cards,
          bypass_times = true,
          extraUse = true,
          exclusive_targets = {player.id},
        },
        true, true)
        if use then
          if #use.tos == 0 then
            if use.card.multiple_targets then
              use.tos = {}
              for _, p in ipairs({player, target}) do
                if not current:isProhibited(player, use.card) then
                  if use.card.skill:modTargetFilter(p.id, {}, player, card, false) then
                    table.insert(use.tos, {player.id})
                  end
                end
              end
            else
              use.tos = {{player.id}}
            end
          end
          room:useCard(use)
        elseif not use and not player.dead then
          room:obtainCard(player, cards, true, fk.ReasonJustMove, player.id, self.name)
        end
      end
    else
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonJustMove, self.name)
    end
  end,

  refresh_events = {fk.EventPhaseStart},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local x = player:getHandcardNum()
    player.room:setPlayerMark(player, "@zishu__yuanjiang-phase", x > 0 and x or "0")
  end,
}

local zishu__suqi = fk.CreateTriggerSkill{
  name = "zishu__suqi",
  anim_type = "drawcard",
  events = {fk.Damage, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      return data.from and not data.from.dead and data.to and not data.to.dead
      and data.from:canPindian(data.to)
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choices = {"zishu__suqi1::"..data.to.id, "zishu__suqi2"}
    local choice = room:askForChoice(data.from, choices, self.name, "#zishu__suqi-choice")
    if choice ~= "zishu__suqi2" then
      local pindian = data.from:pindian({data.to}, self.name)
      for _, p in ipairs ({data.from, data.to}) do
        if pindian.results[data.to.id].winner ~= p and not p:isNude() and not player.dead then
          local chosen = room:askForCardChosen(player, p, "he", self.name)
          local choices2 = {"zishu__suqi_top", "zishu__suqi_bottom"}
          local choicess = room:askForChoice(player, choices2, self.name, "#zishu__suqi-chooose")
          if choicess == "zishu__suqi_top" then
            room:moveCards({
              ids = {chosen},
              from = p.id,
              toArea = Card.DrawPile,
              moveReason = fk.ReasonPut,
              skillName = self.name,
              proposer = player.id,
              moveVisible = true
            })
          else
            room:moveCards({
              ids = {chosen},
              from = p.id,
              toArea = Card.DrawPile,
              moveReason = fk.ReasonPut,
              skillName = self.name,
              proposer = player.id,
              moveVisible = true,
              drawPilePosition = -1
            })
          end
        end
      end
    else
      if data.from:isNude() or player.dead then return end
      local chosen = room:askForCardChosen(player, data.from, "he", self.name)
      local choices2 = {"zishu__suqi_top", "zishu__suqi_bottom"}
      local choicess = room:askForChoice(player, choices2, self.name, "#zishu__suqi-chooose")
      if choicess == "zishu__suqi_top" then
        room:moveCards({
          ids = {chosen},
          from = data.from.id,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          skillName = self.name,
          proposer = player.id,
          moveVisible = true
        })
      else
        room:moveCards({
          ids = {chosen},
          from = data.from.id,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          skillName = self.name,
          proposer = player.id,
          moveVisible = true,
          drawPilePosition = -1
        })
      end
    end
  end,
}

liangxi:addSkill(zishu__yuanjiang)
liangxi:addSkill(zishu__suqi)
AddWinAudio(liangxi)

Fk:loadTranslationTable{
  ["zishu__liangxi"] = "梁习", 
  ["#zishu__liangxi"] = "共济方圆",
  ["cv:zishu__liangxi"] = "易大剧",
  ["illustrator:zishu__liangxi"] = "LiuHeng",
  ["designer:zishu__liangxi"] = "易大剧",

  ["zishu__yuanjiang"] = "远疆",
  [":zishu__yuanjiang"] = "你手牌数减少的阶段结束后，可以亮出牌堆顶的一张牌。若如此做，当前回合角色可以将之对你使用，否则你获得之。",
  ["zishu__suqi"] = "肃齐",
  [":zishu__suqi"] = "你受到或造成伤害后，你可以令伤害来源选择是否与受伤角色拼点。结算后，你将放弃拼点或没赢的角色的一张牌置于牌堆顶或牌堆底。",

  ["@zishu__yuanjiang-phase"] = "远疆",
  ["#zishu__yuanjiang-use"] = "远疆：你可以对 %dest 使用亮出的牌，否则其获得之",
  ["#zishu__suqi-choice"] = "肃齐：请选择一项！",
  ["zishu__suqi_top"] = "置于牌堆顶",
  ["zishu__suqi_bottom"] = "置于牌堆底",
  ["#zishu__suqi-chooose"] = "肃齐：请将选择的牌置于牌堆顶或底！",
  ["zishu__suqi1"] = "与受伤角色 %dest 拼点，没赢者被执行下一项",
  ["zishu__suqi2"] = "令技能发动者将你的一张牌置于牌堆顶或牌堆底",

  ["$zishu__yuanjiang1"] = "鲜卑兵犯，即刻诛灭，头悬街市震慑蛮夷!",
  ["$zishu__yuanjiang2"] = "乌桓王叛，就地斩杀，来日我自奏明魏王!",
  ["$zishu__suqi1"] = "精达事机，威恩兼著，肃齐万里！",
  ["$zishu__suqi2"] = "讨伐匈奴，斩首鲜卑，以清宇内！",
  ["$zishu__liangxi_win_audio"] = "王思亦以义待我，使二人今日蒙魏王拔擢!",
  ["~zishu__liangxi"] = "我以义待王思，纵使死又何惧！",
}

local zishu__shanglve = fk.CreateTriggerSkill{
  name = "zishu__shanglve",
  anim_type = "drawcard",
  events = {fk.CardUsing},
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local use_event = room.logic:getCurrentEvent()
    local x = 0
    local y = 0
    player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function (e)
      if e.id < use_event.id then
        local use = e.data[1]
        if use.from == player.id then
          if use.extra_data and use.extra_data.zishu__shanglve_user == player.id then
            x = x + 1
          else
            y = y + 1
          end
        end
      end
    end, Player.HistoryPhase)
    if x > 0 and y <= 1 then
      player:drawCards(1, self.name)
    end
    local targets = TargetGroup:getRealTargets(data.tos)
    local newmark = {}
    if type(data.tos) ~= "table" then
      player.room:setPlayerMark(player, "@[player]zishu__shanglve", 0)
    else
      for _, p in ipairs(targets) do
        table.insertIfNeed(newmark, room:getPlayerById(p):getLastAlive().id)
        table.insertIfNeed(newmark, room:getPlayerById(p):getNextAlive().id)
      end
      player.room:setPlayerMark(player, "@[player]zishu__shanglve", newmark)
    end
  end,

  refresh_events = {fk.PreCardUse},
  can_refresh = function (self, event, target, player, data)
    return table.find(TargetGroup:getRealTargets(data.tos), function (pid) 
      return table.contains(player:getTableMark("@[player]zishu__shanglve"), pid) end) and player == target
  end,
  on_refresh = function (self, event, target, player, data)
    data.extraUse = true
    data.extra_data = data.extra_data or {}
    data.extra_data.zishu__shanglve_user = player.id
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@[player]zishu__shanglve", 0)
  end,
}

local zishu__shanglve_targetmod = fk.CreateTargetModSkill{
  name = "#zishu__shanglve_targetmod",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and table.contains(player:getTableMark("@[player]zishu__shanglve"), to.id)
  end,
  bypass_distances =  function(self, player, skill, card, to)
    return card and table.contains(player:getTableMark("@[player]zishu__shanglve"), to.id)
  end,
}
zishu__shanglve:addRelatedSkill(zishu__shanglve_targetmod)
wangji:addSkill(zishu__shanglve)
AddWinAudio(wangji)
Fk:loadTranslationTable{
  ["zishu__wangji"] = "王基", 
  ["#zishu__wangji"] = "经兵纬流",
  ["cv:zishu__wangji"] = "幽蝶化烬",
  ["illustrator:zishu__wangji"] = "鬼画府",
  ["designer:zishu__wangji"] = "环己醇",

  ["zishu__shanglve"] = "上略",
  [":zishu__shanglve"] = "你对你上次使用牌的目标角色的上下家使用牌无距离次数限制，且若你本阶段自使用第一张牌后皆如此做，你摸一张牌。"..
  "<font color=\"grey\">皆如此做：你使用牌指定了你上次使用牌的目标角色的上家或下家</font>",

  ["@[player]zishu__shanglve"] = "上略",

  ["$zishu__shanglve1"] = "兼文武之上略，怀济世之弘规。",
  ["$zishu__shanglve2"] = "深算利害，独克制敌，终至禽贼。",
  ["$zishu__wangji_win_audio"] = "佯攻夷陵，直取雄父，吴寇安敢再言渡江？",
  ["~zishu__wangji"] = "诸葛恪新城之败，姜维上络之覆，今复现矣……",
}

local zishu__jiaoxia = fk.CreateViewAsSkill{
  name = "zishu__jiaoxia",
  anim_type = "switch",
  prompt = "#zishu__jiaoxia-viewas",
  pattern = "slash,enemy_at_the_gates",
  card_filter = Util.FalseFunc,
  times = function (self)
    return  4 - Self:usedSkillTimes(self.name, Player.HistoryRound)
  end,
  interaction = function(self)
    local all_names = {"slash","enemy_at_the_gates"}
    local names = U.getViewAsCardNames(Self, "zishu__jiaoxia", all_names)
      if #names > 0 then
        return UI.ComboBox { choices = names, all_choices = all_names }
      end
    end,
  view_as = function(self, cards)
    if not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
    end,
  before_use = function(self, player, use)
    if use.card.name == "enemy_at_the_gates" then
      player:setSkillUseHistory(self.name, 4, Player.HistoryRound)
    end
  end,
  enabled_at_play = function(self, player)
    return 4 - player:usedSkillTimes(self.name, Player.HistoryRound) > 0
  end,
  enabled_at_response = function(self, player, response)
    local pat = Fk.currentResponsePattern
    if response and pat and 4 - player:usedSkillTimes(self.name, Player.HistoryRound) > 0 then
      return Exppattern:Parse(pat):matchExp("slash")
    else 
      return not response and pat and 4 - player:usedSkillTimes(self.name, Player.HistoryRound) > 0
      and (Exppattern:Parse(pat):matchExp("slash") or Exppattern:Parse(pat):matchExp("enemy_at_the_gates"))
    end
  end,
  on_lose = function (self, player, is_death)
    if player:getMark("__hidden_general") == 0 and player:getMark("__hidden_deputy") == 0 then
      player:setSkillUseHistory(self.name, 0, Player.HistoryRound)
    end
  end,
}

local zishu__jieshuo = fk.CreateTriggerSkill{
  name = "zishu__jieshuo",
  anim_type = "defensive",
  events = {fk.EventPhaseStart, fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      return target ~= player and player:hasSkill(self) and target.phase == Player.Play and target:getMark("zishu__jieshuo_"..player.id) > 0
      and target:canUseTo(Fk:cloneCard("duel"), player)
    elseif event == fk.TargetConfirming then
      return target ~= player and player:hasSkill(self) and data.card.trueName == "slash" 
      and room:getPlayerById(data.from) == player and target:getMark("zishu__jieshuo_"..player.id) > 0 
      and table.find(room:getOtherPlayers(target), function(p) return p ~= player and not player:isProhibited(p, data.card) and player:inMyAttackRange(p) end)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      return room:askForSkillInvoke(target, self.name, nil, "#zishu__jieshuo-duel::"..player.id..":"..target:getMark("zishu__jieshuo_"..player.id))
    else
    local targets = {}
    if room:getPlayerById(data.from) ~= player then return false end
    for _, p in ipairs(room:getOtherPlayers(target)) do
      if p ~= player and not player:isProhibited(p, data.card) and player:inMyAttackRange(p) then
        table.insert(targets, p.id)
      end
    end
    if #targets == 0 then return false end
    local plist = room:askForChoosePlayers(target, targets, 1, 1, 
    "#zishu__jieshuo-slash::"..player.id..":"..target:getMark("zishu__jieshuo_"..player.id), self.name, true)
    if #plist > 0 then
      self.cost_data = plist
      return true
    end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      room:removePlayerMark(target, "zishu__jieshuo_"..player.id, 1)
      local card = Fk:cloneCard("duel")
      card.skillName = self.name
      local use = { from = target.id, tos = {{player.id}}, card = card}
      room:useCard (use)
    elseif event == fk.TargetConfirming then
      local to = self.cost_data[1]
      room:setPlayerMark(target, "zishu__jieshuo_"..player.id, 0)
      AimGroup:cancelTarget(data, target.id)
      AimGroup:addTargets(room, data, to)
    end
  end,

  on_acquire = function (self, player, is_start)
    for _, id in ipairs(player.room:getOtherPlayers(player)) do
      player.room:setPlayerMark(id, "zishu__jieshuo_"..player.id, 4)
    end
  end,
  on_lose = function (self, player, is_death)
    if player:getMark("__hidden_general") == 0 and player:getMark("__hidden_deputy") == 0 then
      for _, id in ipairs(player.room:getOtherPlayers(player)) do
        player.room:setPlayerMark(id, "zishu__jieshuo_"..player.id, 0)
      end
    end
  end,
}

yongkai:addSkill(zishu__jiaoxia)
yongkai:addSkill(zishu__jieshuo)

local enemyAtTheGatesSkill = fk.CreateActiveSkill{
  name = "enemy_at_the_gates_skill",
  prompt = "#enemy_at_the_gates_skill",
  can_use = Util.CanUse,
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, player, card)
    return to_select ~= player.id
  end,
  target_filter = Util.TargetFilter,
  on_effect = function(self, room, cardEffectEvent)
    local player = room:getPlayerById(cardEffectEvent.from)
    local to = room:getPlayerById(cardEffectEvent.to)
    local cards = {}
    for _ = 1, 4, 1 do
      local id = room:getNCards(1)[1]
      table.insert(cards, id)
      room:moveCardTo(id, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
      local card = Fk:getCardById(id)
      if card.trueName == "slash" and not player:prohibitUse(card) and not player:isProhibited(to, card) and to:isAlive() then
        card.skillName = self.name
        room:useCard({
          card = card,
          from = player.id,
          tos = { {to.id} },
          extraUse = true,
        })
      end
    end
    room:cleanProcessingArea(cards, self.name)
  end,
}
local enemyAtTheGates = fk.CreateTrickCard{
  name = "&enemy_at_the_gates",
  suit = Card.Spade,
  number = 7,
  skill = enemyAtTheGatesSkill,
}
enemyAtTheGates.package = extension
Fk:addCard(enemyAtTheGates)

Fk:loadTranslationTable{
  ["enemy_at_the_gates"] = "兵临城下", -- 保险起见加个国际服的
  [":enemy_at_the_gates"] = "锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：一名其他角色<br /><b>效果</b>：你依次展示牌堆顶四张牌，若为【杀】，你对目标使用之；若不为【杀】，将此牌置入弃牌堆。",
  ["#enemy_at_the_gates_skill"] = "选择一名其他角色，你依次展示牌堆顶四张牌，若为【杀】，你对其使用之；若不为【杀】，将此牌置入弃牌堆",
  ["enemy_at_the_gates_skill"] = "兵临城下",
}

Fk:loadTranslationTable{
  ["zishu__yongkai"] = "雍闿", 
  ["#zishu__yongkai"] = "腥尘啄碑",
  ["cv:zishu__yongkai"] = "暂无",
  ["illustrator:zishu__yongkai"] = "阵面对决",
  ["designer:zishu__yongkai"] = "此方",

  ["zishu__jiaoxia"] = "骄黠",
  [":zishu__jiaoxia"] = "每轮限四次，你可以：视为使用或打出【杀】，或可以消耗所有剩余次数以视为使用【兵临城下】。",
  ["zishu__jieshuo"] = "桀朔",
  [":zishu__jieshuo"] = "每名其他角色限四次，其可以：出牌阶段开始时，视为对你使用【决斗】；或成为你使用【杀】的目标时，消耗所有剩余次数以转移至你攻击范围内另一名角色。",

  ["#zishu__jiaoxia-viewas"] = "骄黠：你可以视为使用或打出【杀】，或消耗所有剩余次数以视为使用【兵临城下】",
  ["#zishu__jieshuo-duel"] = "桀朔：是否视为对%dest使用决斗？（剩余次数%arg，发动后减1）",
  ["#zishu__jieshuo-slash"] = "桀朔：是否将%dest对你使用的杀转移给其攻击范围内另一名角色？（剩余次数%arg，发动后减至0）",

  ["$zishu__jiaoxia"] = "为了达成目标，力量是必须的。",
  ["$zishu__jieshuo"] = "我必须前进，不论有谁阻挡在我面前。",
  ["~zishu__yongkai"] = "败者…没有借口…",
}

local zishu__ziju = fk.CreateTriggerSkill{
  name = "zishu__ziju",
  anim_type = "switch",
  events = {fk.AfterCardsMove, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.AfterCardsMove then
        for _, move in ipairs(data) do
          if move.to and move.toArea == Player.Hand and move.moveReason == fk.ReasonDraw 
          and not player.room:getPlayerById(move.to).dead and player.room:getPlayerById(move.to) ~= player then
            return (player:getMark("@@zishu__ziju1") > 0 and move.skillName == "phase_draw") or
            (player:getMark("@@zishu__ziju2") > 0 and Fk.all_card_types[move.skillName] and Fk.all_card_types[move.skillName].type == Card.TypeTrick)
            or (player:getMark("@@zishu__ziju3") > 0 and Fk.skills[move.skillName] and
            table.find(player.room.alive_players, function(p) return Fk.skills[move.skillName]:isPlayerSkill(p) end))
          end
        end
      else
        if target.phase == Player.Finish then
          for i = 1 , 3 , 1 do
            if player:getMark("@@zishu__ziju"..i) > 0 then
              return i == target.hp
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for i = 1 , 3 , 1 do
      if player:getMark("@@zishu__ziju"..i) > 0 then
        local n = i + 1 > 3 and 1 or i + 1
        room:setPlayerMark(player, "@@zishu__ziju"..n, 1)
        room:setPlayerMark(player, "@@zishu__ziju"..i, 0)
        break
      end
    end
    if event == fk.AfterCardsMove then
      local get1 = {}
      local get2 = {}
      local theone
      for _, move in ipairs(data) do
        if move.to and move.toArea == Player.Hand and move.moveReason == fk.ReasonDraw and not room:getPlayerById(move.to).dead then
          theone = room:getPlayerById(move.to)
          for _, info in ipairs(move.moveInfo) do
            if table.contains(room:getPlayerById(move.to):getCardIds("h"), info.cardId) then
              if player:cardVisible(info.cardId) then
                table.insertIfNeed(get1, info.cardId)
              else
                table.insertIfNeed(get2, info.cardId)
              end
            end
          end
        end
      end
      local choices = {"zishu__ziju1", "zishu__ziju2"}
      if #get1 == 0 then table.removeOne(choices, "zishu__ziju1") end
      if #get2 == 0 then table.removeOne(choices, "zishu__ziju2") end
      local choice = room:askForChoice(player, choices, self.name, "#zishu__ziju-choice")
      if choice == "zishu__ziju1" then
        local card_data = {}
        table.insert(card_data, {"zishu__ziju-get", get1})
        local chosen = room:askForCardsChosen(player, theone, 1, 1, { card_data = card_data }, self.name)
        player.room:moveCardTo(chosen, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
      else
        player.room:moveCardTo({table.random(get2)}, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
      end
    end
  end,

  on_acquire = function (self, player, is_start)
    local room = player.room
    room:setPlayerMark(player, "@@zishu__ziju1", 1)
    room:setPlayerMark(player, "@@zishu__ziju2", 0)
    room:setPlayerMark(player, "@@zishu__ziju3", 0)
  end,

  on_lose = function (self, player, is_death)
    local room = player.room
    room:setPlayerMark(player, "@@zishu__ziju1", 0)
    room:setPlayerMark(player, "@@zishu__ziju2", 0)
    room:setPlayerMark(player, "@@zishu__ziju3", 0)
  end,
}

local zishu__yinxin = fk.CreateActiveSkill{
  name = "zishu__yinxin",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#zishu__yinxin",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and #Fk:currentRoom():getCardsFromPileByRule("ex_nihilo", 1, "discardPile") > 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:moveCardTo(room:getCardsFromPileByRule("ex_nihilo", 1, "discardPile"), Card.PlayerHand, target, fk.ReasonPrey, self.name, nil, false, player.id)
    if not target.dead then
      room:setPlayerMark(target, "@@zishu__yinxin-skipdraw", 1)
    end
    local enna = false
    while not target.dead do
      if not player.dead then
        local use = U.askForPlayCard(room, target, target:getHandlyIds(true), ".", self.name, "#zishu__yinxin-use", {bypass_times = true}, true)
        if not use then
          break
        elseif use then
          enna = true
          use.extraUse = true
          room:useCard(use)
        end
      end
    end
    if enna and not target.dead then
      room:setPlayerMark(target, "@@zishu__yinxin-skipplay", 1)
    end
  end,
}

local zishu__yinxin_delay = fk.CreateTriggerSkill{
  name = "#zishu__yinxin_delay",

  refresh_events = {fk.EventPhaseChanging},
  can_refresh = function(self, event, target, player, data)
    return player == target and ((data.to == Player.Play and target:getMark("@@zishu__yinxin-skipplay") > 0) or
    (data.to == Player.Draw and target:getMark("@@zishu__yinxin-skipdraw") > 0))
  end,
  on_refresh = function(self, event, target, player, data)
    if data.to == Player.Draw and target:getMark("@@zishu__yinxin-skipdraw") > 0 then
      target.room:setPlayerMark(target, "@@zishu__yinxin-skipdraw", 0)
      target:skip(data.to)
      return true
    else
      target.room:setPlayerMark(target, "@@zishu__yinxin-skipplay", 0)
      target:skip(data.to)
      return true
    end
  end,
}

zishu__yinxin:addRelatedSkill(zishu__yinxin_delay)
SPyongkai:addSkill(zishu__ziju)
SPyongkai:addSkill(zishu__yinxin)

Fk:loadTranslationTable{
  ["zishuSP__yongkai"] = "雍闿", 
  ["#zishuSP__yongkai"] = "其节二三",
  ["cv:zishuSP__yongkai"] = "暂无",
  ["illustrator:zishuSP__yongkai"] = "未知",
  ["designer:zishuSP__yongkai"] = "朱苦力",

  ["zishu__ziju"] = "趑趄",
  [":zishu__ziju"] = "转换技，一名角色因①阶段②锦囊③技能摸牌后，你可以获得其中一张牌。体力值等于序号角色的结束阶段，你可以转换此技能。<br>"..
  "<font color=\"grey\">部分角色技能未填写移牌的技能名，如有此情况导致第三项无法发动，请联系相关扩展的程序员！</font><a href='zishu__ziju_list_href'>名单</a>",
  ["zishu__ziju_list_href"] = "哈哈，不会有写了神人技能的设计师以为天道好轮回了吧，并没有，嘻嘻，以及讲道理你真的找不到程序员的QQ号吗，我不信(。-ω-)zzz",
  ["zishu__yinxin"] = "狺信",
  [":zishu__yinxin"] = "出牌阶段限一次，你可以令一名其他角色获得弃牌堆中的一张【无中生有】,令其跳过下个摸牌阶段，然后其可以使用任意张牌，跳过下个出牌阶段。",

  ["@@zishu__ziju1"] = "趑趄①",
  ["@@zishu__ziju2"] = "趑趄②",
  ["@@zishu__ziju3"] = "趑趄③",
  ["#zishu__ziju-choice"] = "趑趄：请选择一项",
  ["zishu__ziju1"] = "获得其中一张对你可见的牌",
  ["zishu__ziju2"] = "随机获得其中一张不可见的牌",
  ["zishu__ziju-get"] = "趑趄",
  ["#zishu__yinxin_delay"] = "狺信",
  ["#zishu__yinxin"] = "狺信：令一名角色获得弃牌堆一张【无中生有】，其跳过下个摸牌阶段",
  ["#zishu__yinxin-use"] = "狺信：是否依次使用任意张牌？若流程中您使用了牌，跳过下个出牌阶段",
  ["@@zishu__yinxin-skipdraw"] = "跳摸",
  ["@@zishu__yinxin-skipplay"] = "跳出",

  ["$zishu__ziju"] = "为了达成目标，力量是必须的。",
  ["$zishu__yinxin"] = "我必须前进，不论有谁阻挡在我面前。",
  ["~zishuSP__yongkai"] = "败者…没有借口…",
}

local zishu__eyao = fk.CreateTriggerSkill{
  name = "zishu__eyao",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    return target == player and player:hasSkill(self) and table.find(room.discard_pile, function(id) return Fk:getCardById(id).trueName == "jink" end)
    and table.find(room.discard_pile, function(id) return Fk:getCardById(id).type == Card.TypeTrick end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not player.dead then
      local ids = {}
      for _ , id in ipairs (room.discard_pile) do
        if Fk:getCardById(id).trueName == "jink" then
          table.insertIfNeed(ids, id)
        end
      end
      room:askForYiji(player, ids, room:getAllPlayers(), self.name, 1, 1, nil, ids)
    end
    if not player.dead then
      local ids = {}
      for _ , id in ipairs (room.discard_pile) do
        if Fk:getCardById(id).type == Card.TypeTrick then
          table.insertIfNeed(ids, id)
        end
      end
      if #ids == 0 then return end
      --沟槽的遗计没法追踪分配牌的数组，试了几次都不行，还是用幽蝶系列智慧吧
      local success, dat = room:askForUseActiveSkill(player, "teyvat__cardplace", "zishu__eyao-put", false,
      {all_choices_exclu = {"ToHand"}, only_card = ids,  expand_pile = ids})
      if success and dat then
        local to = room:getPlayerById(dat.targets[1])
        room:moveCardTo(dat.cards, Player.Hand, to, fk.ReasonGive, self.name, nil, true, player.id)
        if not player.dead then
          local mark = player:getTableMark("@$zishu__eyao")
          table.insertIfNeed(mark, Fk:getCardById(dat.cards[1]).trueName)
          room:setPlayerMark(player, "@$zishu__eyao", #mark > 0 and mark or 0)
        end
      end
    end
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.from == player.id and move.to ~= player.id then
          for _, info in ipairs(move.moveInfo) do
            return Fk:getCardById(info.cardId).trueName == "jink"
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@$zishu__eyao", 0)
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@$zishu__eyao", 0)
  end,
}

local zishu__eyao_prohibit = fk.CreateProhibitSkill{
  name = "#zishu__eyao_prohibit",
  prohibit_use = function(self, player, card)
    return table.find(Fk:currentRoom().alive_players, function(p) return table.contains(p:getTableMark("@$zishu__eyao"), card.name) end)
  end,
}

local zishu__qinduan = fk.CreateActiveSkill{
  name = "zishu__qinduan",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#zishu__qinduan",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local reward = {"thunder__slash","iron_chain","lure_tiger"}
    local use = U.askForUseVirtualCard(player.room, player, reward, nil, self.name, nil, false, true, false, true, nil, false)
    if not target.dead then
      local use2 = U.askForUseVirtualCard(player.room, target, reward, nil, self.name, nil, false, true, false, true, nil, false)
      if use and use2 and use.card.name == use2.card.name and not target.dead then
        target:turnOver()
      end
      if use and use2 and table.find(TargetGroup:getRealTargets(use.tos), function(id) return table.contains(TargetGroup:getRealTargets(use2.tos), id) end) 
      and not player.dead then
        player:turnOver()
      end
    end
  end,
}

zishu__eyao:addRelatedSkill(zishu__eyao_prohibit)
yanghong:addSkill(zishu__eyao)
yanghong:addSkill(zishu__qinduan)

Fk:loadTranslationTable{
  ["zishu__yanghong"] = "杨洪", 
  ["#zishu__yanghong"] = "经事唯忠",
  ["cv:zishu__yanghong"] = "暂无",
  ["illustrator:zishu__yanghong"] = "未知",
  ["designer:zishu__yanghong"] = "朱苦力",

  ["zishu__eyao"] = "扼要",
  [":zishu__eyao"] = "当你受到伤害后，你可以分配弃牌堆【闪】与锦囊牌各一张，然后至你失去【闪】前，与后者同名的牌无法被使用。",
  ["zishu__qinduan"] = "擒断",
  [":zishu__qinduan"] = "出牌阶段限一次，你可以与一名其他角色依次从雷【杀】、【铁索连环】、【调虎离山】中选择并视为使用一张，"..
  "若选择的牌名/目标有相同，其/你翻面。",

  ["zishu__eyao-put"] = "扼要：分配弃牌堆一张锦囊牌，至你失去【闪】前，同名的牌无法被使用",
  ["@$zishu__eyao"] = "扼要",
  ["#zishu__qinduan"] = "擒断：选择一名其他角色与你用牌",

  ["$zishu__eyao"] = "为了达成目标，力量是必须的。",
  ["$zishu__qinduan"] = "我必须前进，不论有谁阻挡在我面前。",
  ["~zishu__yanghong"] = "败者…没有借口…",
}

local zishu__qianshang = fk.CreateActiveSkill{
  name = "zishu__qianshang",
  anim_type = "offensive",
  prompt = "#zishu__qianshang",
  card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return player:canUse(Fk:cloneCard("analeptic")) and not player:isNude()
    and not player:getNextAlive():isNude() and not player:getLastAlive():isNude()
    and player:getNextAlive() ~= player and player:getLastAlive() ~= player
  end,
  card_filter = function(self, to_select, selected, targets)
    return #selected == 0
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    local tar = Fk:currentRoom():getPlayerById(to_select)
    return Self:canUseTo(Fk:cloneCard("analeptic"), tar) and (tar == Self or tar == Self:getLastAlive() or tar == Self:getNextAlive())
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local lastone = room:getPlayerById(player:getLastAlive().id)
    local nextone = room:getPlayerById(player:getNextAlive().id)
    local analeptic = Fk:cloneCard("analeptic")
    analeptic.skillName = self.name
    local n = 0
    for i = 1, 50 ,1 do --50个应该够用
      if #target:getTableMark("zishu__qianshang"..i.."-turn") == 0 then
        n = 0 + i
        break
      end
    end
    if lastone ~= nextone then
      local cards1 = room:askForCardsChosen(player, lastone, 1, 1, "he", self.name, "#zishu__qianshang1")
      local cards2 = room:askForCardsChosen(player, nextone, 1, 1, "he", self.name, "#zishu__qianshang2")
      for _, id in ipairs({effect.cards, cards1, cards2}) do
        room:addTableMark(target, "zishu__qianshang"..n.."-turn", id[1])
        analeptic:addSubcard(id[1])
      end
    elseif lastone == nextone then
      local cards1 = room:askForCardsChosen(player, lastone, math.min(2, #lastone:getCardIds("he")),
      math.min(2, #lastone:getCardIds("he")), "he", self.name, "#zishu__qianshang3")
      for _, id in ipairs({effect.cards, cards1}) do
        room:addTableMark(target, "zishu__qianshang"..n.."-turn", id[1])
        analeptic:addSubcard(id[1])
      end
    end
    room:useCard{
      from = player.id,
      card = analeptic,
      tos = { { target.id } },
    }
  end,
}
local zishu__qianshang_trigger = fk.CreateTriggerSkill{
  name = "#zishu__qianshang_trigger",
  anim_type = "drawcard",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    for i = 1, 50 ,1 do --50个应该够用
      return #player:getTableMark("zishu__qianshang"..i.."-turn") > 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    for i = 1, 50 ,1 do --50个应该够用
      if player.dead then break end
      if #player:getTableMark("zishu__qianshang"..i.."-turn") > 0 then
        local toget = {}
        for _, t in ipairs(player:getTableMark("zishu__qianshang"..i.."-turn")) do
          if table.contains(player.room.discard_pile, t) then
            table.insertIfNeed(toget, t)
          end
        end
        player.room:setPlayerMark(player, "zishu__qianshang"..i.."-turn", 0)
        player.room:moveCardTo(toget, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, true, player.id)
      end
    end
  end,
}

local zishu__ruwo = fk.CreateViewAsSkill{
  name = "zishu__ruwo",
  pattern = "collateral",
  prompt = "#zishu__ruwo",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local c = Fk:cloneCard("collateral")
    c.skillName = self.name
    return c
  end,
  before_use = function(self, player, use)
    use.extra_data = use.extra_data or {}
    use.extra_data.zishu__ruwo_user = player.id
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  enabled_at_response = Util.FalseFunc,
}
local zishu__ruwo_delay = fk.CreateTriggerSkill{
  name = "#zishu__ruwo_delay",
  mute = true,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return not player.dead and table.contains(data.card.skillNames, "zishu__ruwo")
    and data.extra_data and data.extra_data.zishu__ruwo_user == player.id and data.extra_data.zishu__ruwo_weapon
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    if data.extra_data then
      for _, d in ipairs(data.extra_data.zishu__ruwo_weapon) do
        if player.dead then break end
        if table.contains(player:getCardIds("h"), d) and table.find(player.room.alive_players, function (p) 
          return U.canMoveCardIntoEquip(p, d, false) end) then
            local tos = player.room:askForChoosePlayers(player, table.map(table.filter(player.room.alive_players, function (p) 
            return U.canMoveCardIntoEquip(p, d, false) end), Util.IdMapper), 1, 1, "#zishu__ruwo-delay:::"..Fk:getCardById(d):toLogString(), self.name, false)
            player.room:moveCardIntoEquip(player.room:getPlayerById(tos[1]), d, self.name, false, player)
        end
      end
    end
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.moveReason == fk.ReasonGive and move.skillName == "collateral" then
        local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
        if use_event ~= nil then
          local use = use_event.data[1]
          if (use.extra_data or {}).zishu__ruwo_user == player.id then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if player.room:getCardArea(info.cardId) == Card.PlayerHand and Fk:getCardById(info.cardId).sub_type == Card.SubtypeWeapon then
          local use_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
          if use_event ~= nil then
            local use = use_event.data[1]
            if (use.extra_data or {}).zishu__ruwo_user == player.id then
              use.extra_data = use.extra_data or {}
              use.extra_data.zishu__ruwo_weapon = use.extra_data.zishu__ruwo_weapon or {}
              table.insert(use.extra_data.zishu__ruwo_weapon, info.cardId)
            end
          end
         end
      end
    end
  end,
}

zishu__qianshang:addRelatedSkill(zishu__qianshang_trigger)
panzhang:addSkill(zishu__qianshang)
zishu__ruwo:addRelatedSkill(zishu__ruwo_delay)
panzhang:addSkill(zishu__ruwo)

Fk:loadTranslationTable{
  ["zishu__panzhang"] = "潘璋", 
  ["#zishu__panzhang"] = "醉凛阵鸣",
  ["cv:zishu__panzhang"] = "幽蝶化烬",
  ["illustrator:zishu__panzhang"] = "阵面对决",
  ["designer:zishu__panzhang"] = "牧孖",

  ["zishu__qianshang"] = "千觞",
  [":zishu__qianshang"] = "出牌阶段，你可以将你，上家，下家各一张牌当【酒】对其中一名角色使用，然后本回合下次有角色造成伤害后，此牌目标获得底牌。",
  ["zishu__ruwo"] = "入握",
  [":zishu__ruwo"] = "出牌阶段限一次，你可以视为使用一张【借刀杀人】，然后将因此获得的武器牌置入一名角色的装备区。",

  ["#zishu__qianshang"] = "千觞：请选择你要用于转化的牌与以此法使用酒的角色，上下家的牌随后选择",
  ["#zishu__qianshang1"] = "千觞: 请选择上家的一张牌用于转化",
  ["#zishu__qianshang2"] = "千觞: 请选择下家的一张牌用于转化",
  ["#zishu__qianshang3"] = "千觞: 上下家一致，请选择其的两张牌或不足两张的所有牌用于转化",
  ["#zishu__qianshang_trigger"] = "千觞",
  ["#zishu__ruwo"] = "入握：是否视为使用【借刀杀人】，且结算后分配武器牌？",
  ["#zishu__ruwo_delay"] = "入握",
  ["#zishu__ruwo-delay"] = "入握：请将此法获得的武器牌 %arg 置入一名角色装备区内！",

  ["$zishu__qianshang1"] = "军中设市，得四方美酿，邀诸君共饮。",
  ["$zishu__qianshang2"] = "锦衣玉食到手，杀几个丘八算什么？",
  ["$zishu__ruwo1"] = "青龙偃月不折，何以铸我固陵刀？",
  ["$zishu__ruwo2"] = "尔所倚仗，长刀快马，今已入我之握！",
  ["~zishu__panzhang"] = "蒙我主厚爱，免我百死，恨未能建功以报...",
}

local zishu__zhilian = fk.CreateTriggerSkill{
  name = "zishu__zhilian",
  anim_type = "offensive",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
    data.extra_data and data.extra_data.combo_skill and data.extra_data.combo_skill[self.name]
  end,
  on_cost = function (self, event, target, player, data)
    local targetlist = table.filter(player.room:getAllPlayers(), function (id) return id:isWounded() end)
    local targets = table.map(targetlist, Util.IdMapper)
    if #targets == 0 then player.room:setPlayerMark(player, "@zishu__zhilian", 0) return end
    local tar = player.room:askForChoosePlayers(player, targets, 1, 1, "#zishu__zhilian-choose", self.name, true, false)
    if #tar > 0 then
      self.cost_data = tar[1]
      return true
    else
      player.room:setPlayerMark(player, "@zishu__zhilian", 0)
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@zishu__zhilian", 0)
    local to = room:getPlayerById(self.cost_data)
    room:recover({
      who = to,
      num = 1,
      recoverBy = player,
      skillName = self.name
    })
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(self, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("@zishu__zhilian")
    local nocombo = true
    if not table.contains(mark, data.card:getSuitString(true)) and data.card.suit ~= Card.NoSuit then
      table.insertIfNeed(mark, data.card:getSuitString(true))
      room:setPlayerMark(player, "@zishu__zhilian", #mark > 0 and mark or 0)
      nocombo = false
    elseif table.contains(mark, data.card:getSuitString(true)) and data.card.suit ~= Card.NoSuit and nocombo then
      local _, ret = room:askForUseActiveSkill(player, "zishu__zhilian_active", "#zishu__zhilian-invoke", true)
      if ret then
        local cards = ret.cards
        if #cards == 2 then
          room:recastCard(cards, player, self.name)
          for _, id in ipairs (mark) do
            if not table.find(cards, function(pid) return Fk:getCardById(pid):getSuitString(true) == id end) then
              table.removeOne(mark, id)
            end
          end
          if not player.dead then
            room:setPlayerMark(player, "@zishu__zhilian", #mark > 0 and mark or 0)
          end
        end
      else
        room:setPlayerMark(player, "@zishu__zhilian", 0)
      end
    end
    if #mark == 4 then
      data.extra_data = data.extra_data or {}
      data.extra_data.combo_skill = data.extra_data.combo_skill or {}
      data.extra_data.combo_skill[self.name] = true
    return
    end
  end,

  on_lose = function (self, player, is_death)
    local room = player.room
    room:setPlayerMark(player, "@zishu__zhilian", 0)
  end,
}

local zishu__zhilian_active = fk.CreateActiveSkill{
  name = "zishu__zhilian_active",
  mute = true,
  min_card_num = 2,
  max_card_num = 2,
  target_num = 0,
  card_filter = function(self, to_select, selected)
    if Self:prohibitDiscard(Fk:getCardById(to_select)) then return false end
    if #selected == 0 then
      return true
    else
      return table.every(selected, function(id) return Fk:getCardById(to_select).type == Fk:getCardById(id).type end)
    end
  end,
}

local zishu__chousu = fk.CreateTriggerSkill{
  name = "zishu__chousu",
  anim_type = "drawcard",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local suitlist = {}
      player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function (e)
        local use = e.data[1]
        if table.contains(TargetGroup:getRealTargets(use.tos), player.id)
        and use.card.color ~= Card.NoColor then
        table.insertIfNeed(suitlist, use.card.color)
        end
      end, Player.HistoryPhase)
      return #suitlist == 1
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local suitlist = {}
    local propmt
    room.logic:getEventsOfScope(GameEvent.UseCard, 999, function (e)
      local use = e.data[1]
      if table.contains(TargetGroup:getRealTargets(use.tos), player.id)
      and use.card.color ~= Card.NoColor then
      table.insertIfNeed(suitlist, use.card.color)
      propmt = use.card:getColorString()
      end
    end, Player.HistoryPhase)
    while not player.dead do
      player:drawCards(1, self.name)
      if not player.dead then
        local use = U.askForPlayCard(room, player, player:getHandlyIds(true), ".", self.name,
        "#zishu__chousu-use:::"..propmt, {bypass_times = true}, true)
        if not use then
          break
        elseif use then
          use.extraUse = true
          room:useCard(use)
          if use.card.color == Card.NoColor or use.card.color == suitlist[1] then
            break
          end
        end
      end
    end
  end,
}

Fk:addSkill(zishu__zhilian_active)
panshu:addSkill(zishu__zhilian)
panshu:addSkill(zishu__chousu)
Fk:loadTranslationTable{
  ["zishu__panshu"] = "潘淑", 
  ["#zishu__panshu"] = "瑶台遗韵",
  ["cv:zishu__panshu"] = "暂无",
  ["illustrator:zishu__panshu"] = "匠人绘",
  ["designer:zishu__panshu"] = "yyuan",

  ["zishu__zhilian"] = "织连",
  [":zishu__zhilian"] = "连招技(四张花色不同的牌)，你可以令一名角色回复1点体力。连招中断时，你可以重铸两张类型相同的牌，保留被重铸花色的进度。",
  ["zishu__chousu"] = "愁诉",
  [":zishu__chousu"] = "你仅被一种颜色的牌指定过的阶段结束时，你摸一张牌且可以使用一张牌，若使用的牌为另一颜色，重复此流程。",

  ["@zishu__zhilian"] = "织连",
  ["zishu__zhilian_active"] = "织连",
  ["#zishu__zhilian-choose"] = "织连：是否令一名角色回复1点体力？",
  ["#zishu__zhilian-invoke"] = "织连：是否重铸两张同类别牌，并保留重铸牌花色的连招进度？",
  ["#zishu__chousu-use"] = "愁诉：你可以使用牌，若使用牌颜色为 %arg 或 无色 则在使用后<font color=\"green\">中止流程</font>，否则可以重复摸牌用牌。",

  ["$zishu__zhilian"] = "为了达成目标，力量是必须的。",
  ["$zishu__chousu"] = "我必须前进，不论有谁阻挡在我面前。",
  ["~zishu__panshu"] = "败者…没有借口…",
}

local zishu__duoce = fk.CreateTriggerSkill{
  name = "zishu__duoce",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player, false), function(p) return player:canPindian(p) end)
    return player:hasSkill(self) and target == player and target.phase == Player.Start and not player:isKongcheng() and #targets > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player, false), function(p) return player:canPindian(p) end)
    if #targets > 0 then
      local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#zishu__duoce-choose", self.name, true)
      if #tos > 0 then
        self.cost_data = tos[1]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local pindian = player:pindian({to}, self.name)
    if pindian.results[self.cost_data].winner ~= player then
      local targets1 = {}
      for _, p in ipairs(room:getOtherPlayers(player, false)) do
      local lure = Fk:cloneCard("lure_tiger")
        if not player:prohibitUse(lure) and not player:isProhibited(p, lure) and p ~= to then
          table.insert(targets1, p.id)
        end
      end
      if #targets1 > 0 and not player.dead then
        local tos1 = room:askForChoosePlayers(player, targets1, 1, 2, nil, self.name, false)
        room:useVirtualCard("lure_tiger", nil, player, table.map(tos1, Util.Id2PlayerMapper), self.name, true)
      end
    end
    if pindian.results[self.cost_data].winner ~= to then
      local targets2 = {}
      for _, p in ipairs(room:getOtherPlayers(to, false)) do
      local lure = Fk:cloneCard("lure_tiger")
        if not to:prohibitUse(lure) and not to:isProhibited(p, lure) and p ~= player then
          table.insert(targets2, p.id)
        end
      end
      if #targets2 > 0 and not to.dead then
        local tos2 = room:askForChoosePlayers(to, targets2, 1, 2, nil, self.name, false)
        room:useVirtualCard("lure_tiger", nil, to, table.map(tos2, Util.Id2PlayerMapper), self.name, true)
      end
    end
    if pindian.results[self.cost_data].winner ~= nil then
      local winner = pindian.results[self.cost_data].winner
      if winner then
        if winner.dead or not winner:canUse(Fk:cloneCard("archery_attack")) then return end
        U.askForUseVirtualCard(room, winner, "archery_attack", nil, self.name, nil, false, true, true)
      end
    end
  end
}

local zishu__shuairan = fk.CreateTriggerSkill{
  name = "zishu__shuairan",
  anim_type = "recover",
  events = {fk.EnterDying},
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "@zishu__shuairan", 1) --这个是次数标记，实际上是获取发动次数触发崩血
    player.room:recover{ who = player, num = 3, recoverBy = player, skillName = self.name }
  end,

  refresh_events = {fk.RoundEnd},
  can_refresh = function (self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    return player:usedSkillTimes("zishu__shuairan", Player.HistoryGame) > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:loseHp(player, player:usedSkillTimes("zishu__shuairan", Player.HistoryGame), self.name)
  end,

  on_acquire = function (self, player, is_start)
    player.room:setPlayerMark(player, "@zishu__shuairan", player:usedSkillTimes("zishu__shuairan", Player.HistoryGame))
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@zishu__shuairan", 0)
  end,
}

shenpei:addSkill(zishu__duoce)
shenpei:addSkill(zishu__shuairan)
AddWinAudio(shenpei)

Fk:loadTranslationTable{
  ["zishu__shenpei"] = "审配", 
  ["#zishu__shenpei"] = "烈誓孑城",
  ["cv:zishu__shenpei"] = "幽蝶化烬",
  ["illustrator:zishu__shenpei"] = "未知",
  ["designer:zishu__shenpei"] = "朱苦力",

  ["zishu__duoce"] = "度策",
  [":zishu__duoce"] = "准备阶段，你可以拼点；没赢的角色视为使用一张不能指定拼点角色的【调虎离山】，然后赢的角色视为使用一张【万箭齐发】。",
  ["zishu__shuairan"] = "率然",
  [":zishu__shuairan"] = "你进入濒死状态时，你可以回复3点体力。每轮结束时，你失去X点体力，X为你因此技能回复体力的次数。",

  ["#zishu__duoce-choose"] = "度策：是否选择一名角色与你拼点？",
  ["@zishu__shuairan"] = "率然",

  ["$zishu__duoce1"] = "兵法云“十围五攻”，此之谓也。",
  ["$zishu__duoce2"] = "敌疲我盛，今不时取，后难图也！",
  ["$zishu__shuairan1"] = "尔言弩多？犹恨其少！",
  ["$zishu__shuairan2"] = "吾主在北，岂可面南？",
  ["$zishu__shenpei_win_audio"] = "今以明公之神武，跨河朔之强众，伐曹譬若覆手！",
  ["~zishu__shenpei"] = "正南再拜我居北之主，臣死不负忠…",
}

local zishu__zhiwang = fk.CreateTriggerSkill{
  name = "zishu__zhiwang",
  anim_type = "control",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.hp > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local n = player.hp
    local targets = {}
    for _, p in ipairs(room:getAlivePlayers()) do
      table.insert(targets, p.id)
    end
    local tos = room:askForChoosePlayers(player, targets, 1, n, "#zishu__zhiwang-cost", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.simpleClone(self.cost_data.tos)
    room:sortPlayersByAction(targets)
    local tolist = {}
    for _, id in ipairs(targets) do
      local pid = room:getPlayerById(id)
      if not pid.dead then
      local get = {}
      local name
      if Fk.all_card_types["shade"] then
        name = "shade"
      elseif Fk.all_card_types["rfenghou__shade"] then
        name = "rfenghou__shade"
      elseif Fk.all_card_types["tey__shade"] then
        name = "tey__shade"
      end
      assert(name, "服务器未加入【影】！请联系管理员安装“江山如故”，或启用“提瓦特卡牌”“封侯卡牌”等添加【影】的卡牌包！")
      table.insert(get, room:printCard(name, 1, 1).id)
      room:setCardMark(Fk:getCardById(get[1]), MarkEnum.DestructIntoDiscard, 1)
      room:obtainCard(pid, get, true, fk.ReasonJustMove, id, self.name, {"@zishu__zhiwang-inhand", Fk:translate(pid.general, "zh_CN")})
        if Fk:getCardById(get[1]):getMark("@zishu__zhiwang-inhand") ~= 0 then
          table.insertIfNeed(tolist, get[1])
        end
      end
    end
    if not player.dead and #tolist > 0 then
      local ctolist = player.room:askForCard(player, 0, #tolist, false, self.name, false, tostring(Exppattern{ id = tolist }), "#zishu__zhiwang-turnover", tolist)
      for _, id in ipairs(ctolist) do
        room:setCardMark(Fk:getCardById(id), "@@ShownCards-inhand", 1)
      end
    end
    for _, p in ipairs(room:getAllPlayers()) do
      for _, id in ipairs(p:getCardIds("h")) do
        room:setCardMark(Fk:getCardById(id), "@zishu__zhiwang-inhand", 0)
      end
    end
  end,
}

local zishu__zhiwang_filter = fk.CreateFilterSkill{
  name = "#zishu__zhiwang_filter",
  mute = true,
  card_filter = function(self, card, player)
    local plist = {}
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if not p:isKongcheng() then
        for _, id in ipairs(p:getCardIds("h")) do
          local carding = Fk:getCardById(id, true)
          if string.find(Fk:translate(carding.trueName, "zh_CN"), "影") and Fk:translate(carding.trueName, "zh_CN"):len() == 1
          and carding:getMark("@@ShownCards-inhand") > 0 then
            table.insertIfNeed(plist, id)
          end
        end
      end
    end
    if #plist == 1 and table.find(Fk:currentRoom().alive_players, function(p) return p:hasSkill(self) end) then
      return string.find(Fk:translate(card.trueName, "zh_CN"), "影") and Fk:translate(card.trueName, "zh_CN"):len() == 1
      and card:getMark("@@ShownCards-inhand") > 0
    end
  end,
  view_as = function(self, card)
    local c = Fk:cloneCard("savage_assault", card.suit, card.number)
    c.skillName = self.name
    return c
  end,
}

local zishu__duquan = fk.CreateTriggerSkill{
  name = "zishu__duquan",
  anim_type = "offensive",
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return
      target == player and
      data.card.is_damage_card and
      player:hasSkill(self) and
      ( table.find(AimGroup:getAllTargets(data.tos), function (id)
        return not player.room:getPlayerById(id):isKongcheng()
      end) and not player.room:getPlayerById(data.from):isKongcheng()
      )
      and
      (event == fk.TargetConfirmed or data.firstTarget)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(AimGroup:getAllTargets(data.tos), function (id)
      return not room:getPlayerById(id):isKongcheng()
    end)
    if #targets == 0 then return false end
    local tar = room:askForChoosePlayers(player, targets, 1, 1, "#zishu__duquan-choose", self.name, true, false)
      if #tar > 0 then
        self.cost_data = {tos = tar}
        return true
      end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local source = room:getPlayerById(data.from)
    local to = room:getPlayerById(self.cost_data.tos[1])
    local damageplus = false
    if not source:isKongcheng() then
      local chosen1 = room:askForCardChosen(player, source, "h", self.name)
      if Fk:getCardById(chosen1).suit == Card.Spade then
        damageplus = true
      end
      room:throwCard({chosen1}, self.name, source, player)
    end
    if not to:isKongcheng() and not player.dead then
      local chosen2 = room:askForCardChosen(player, to, "h", self.name)
      if Fk:getCardById(chosen2).suit == Card.Spade then
        damageplus = true
      end
      room:throwCard({chosen2}, self.name, to, player)
    end
    if damageplus then
      data.extra_data = data.extra_data or {}
      data.extra_data.zishu__duquan = data.extra_data.zishu__duquan or {}
      table.insert(data.extra_data.zishu__duquan, player.id)
    end
  end,

  refresh_events = {fk.DamageCaused},
  can_refresh = function(self, event, target, player, data)
    if data.card == nil or data.chain then return false end
    local room = player.room
      local card_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if not card_event then return false end
      local use = card_event.data[1]
      if use.extra_data then
        local duquan_data = use.extra_data.zishu__duquan
        if duquan_data then
          return table.contains(use.extra_data.zishu__duquan, player.id)
        end
      end
  end,
  on_refresh = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,
}
zishu__zhiwang:addRelatedSkill(zishu__zhiwang_filter)
duosidawang:addSkill(zishu__zhiwang)
duosidawang:addSkill(zishu__duquan)

Fk:loadTranslationTable{
  ["zishu__duosidawang"] = "朵思大王", 
  ["#zishu__duosidawang"] = "抟沙振夷",
  ["cv:zishu__duosidawang"] = "暂无",
  ["illustrator:zishu__duosidawang"] = "阵面对决",
  ["designer:zishu__duosidawang"] = "秋风",

  ["zishu__zhiwang"] = "智望",
  [":zishu__zhiwang"] = "回合开始时，你可以令至多体力值名角色各获得一张【影】且你明置其中任意张。游戏内唯一的明置【影】视为【南蛮入侵】。",
  ["zishu__duquan"] = "毒泉",
  [":zishu__duquan"] = "当你成为伤害牌的使用者或目标后，你可以弃置使用者和一名目标角色各一张手牌，若弃置过♠牌，此牌的伤害基数+1。",

  ["@zishu__zhiwang-inhand"] = "",
  ["#zishu__zhiwang_filter"] = "智望",
  ["#zishu__zhiwang-cost"] = "智望：是否令至多体力值名角色各获得一张【影】？",
  ["#zishu__zhiwang-turnover"] = "智望：是否明置其中任意张【影】？",
  ["#zishu__duquan-choose"] = "是否发动 毒泉，选择一名伤害牌目标，弃置使用者与其的一张手牌，弃置♠牌则伤害基数+1。",

  ["$zishu__zhiwang"] = "为了达成目标，力量是必须的。",
  ["$zishu__duquan"] = "我必须前进，不论有谁阻挡在我面前。",
  ["~zishu__duosidawang"] = "败者…没有借口…",
}

local zishu__buqun = fk.CreateTriggerSkill{
  name = "zishu__buqun",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart, fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Finish
    elseif event == fk.CardUsing then
      return target == player and player:hasSkill(self) and table.find(player.room:getAllPlayers(), 
      function(p) return p:getHandcardNum() == player:getHandcardNum() and not p:isNude() end)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player.room:askForSkillInvoke(player, self.name, nil)
    elseif event == fk.CardUsing then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      while not player.dead do
        player:drawCards(1, self.name)
        if not table.find(player.room:getOtherPlayers(player), function(p) return p:getHandcardNum() == player:getHandcardNum() end) then
          break
        end
      end
    elseif event == fk.CardUsing then
      local get = player.room:askForChoosePlayers(player, table.map(table.filter(player.room:getAllPlayers(),
      function(p) return p:getHandcardNum() == player:getHandcardNum() and not p:isNude() end), Util.IdMapper), 1, 1, "#zishu__buqun-choose", self.name, false)
      if #get > 0 then
        local to =  player.room:getPlayerById(get[1])
        local cards = player.room:askForCardsChosen(player, to, 1, 1, "he", self.name)
        if #cards > 0 then
          to:addToPile("$zishu__buqun", cards, false, self.name)
        end
      end
    end
  end,

  refresh_events = {fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return #player:getPile("$zishu__buqun") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:moveCardTo(player:getPile("$zishu__buqun"), Player.Hand, player, fk.ReasonPrey, self.name)
  end,
}

local zishu__bugu = fk.CreateTriggerSkill{
  name = "zishu__bugu",
  anim_type = "masochism",
  events = {fk.EventPhaseStart, fk.Death},
  can_trigger = function(self, event, target, player, data)
    if target == player then
      if event == fk.EventPhaseStart then
        return player:hasSkill(self) and player.phase == Player.Start
      elseif event == fk.Death then
        return player:hasSkill(self, false, true)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return true
    elseif event == fk.Death then
      local to = player.room:askForChoosePlayers(player, table.map(player.room:getAlivePlayers(), Util.IdMapper), 1, 1, "#zishu__bugu2-choose", self.name, true)
      if #to > 0 then
        self.cost_data = to[1]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local targets = {}
      for _, p in ipairs(player.room:getOtherPlayers(player)) do
        table.insert(targets, p)
      end
      for _, p in ipairs(targets) do
        if not p.dead and not player.dead then
          local comfirm1 = player.room:askForSkillInvoke(p, self.name, nil, "#zishu__bugu1-choose::"..player.id)
          if comfirm1 then
            local comfirm2 = player.room:askForSkillInvoke(player, self.name, nil, "#zishu__bugu1-comfirm::"..p.id)
            if comfirm2 then
              U.swapHandCards(player.room, player, player, p, self.name)
            end
          end
        end
      end
    elseif event == fk.Death then
    local to = player.room:getPlayerById(self.cost_data)
    local comfirm3 = player.room:askForSkillInvoke(to, self.name, nil, "#zishu__bugu2-comfirm::"..player.id)
      if comfirm3 then
        U.swapHandCards(player.room, player, player, to, self.name)
      end
    end
  end,
}
shantao:addSkill(zishu__buqun)
shantao:addSkill(zishu__bugu)
Fk:loadTranslationTable{
  ["zishu__shantao"] = "山涛", 
  ["#zishu__shantao"] = "千仞振嵩",
  ["cv:zishu__shantao"] = "暂无",
  ["illustrator:zishu__shantao"] = "UCHIDA",
  ["designer:zishu__shantao"] = "朱苦力",

  ["zishu__buqun"] = "不群",
  [":zishu__buqun"] = "结束阶段，你可以摸一张牌并重复至手牌数全场唯一。你使用牌时，须将一名手牌数与你相同的角色一张牌移出游戏至回合结束。",
  ["zishu__bugu"] = "不孤",
  [":zishu__bugu"] = "准备阶段，经你同意，其他角色可以与你交换手牌。你死亡时，经其他角色同意，你可以与其交换手牌。",

  ["#zishu__buqun-choose"] = "不群：请选择一名手牌数等于你的角色",
  ["$zishu__buqun"] = "不群",
  ["#zishu__bugu1-choose"] = "不孤：是否向%dest发起交换手牌的请求？若其同意，你与其交换手牌。",
  ["#zishu__bugu1-comfirm"] = "不孤：%dest请求与你交换手牌，点确定同意，点取消拒绝。",
  ["#zishu__bugu2-choose"] = "不孤：请选择一名其他角色，若其同意，你与其交换手牌。",
  ["#zishu__bugu2-comfirm"] = "不孤：%dest请求与你交换手牌，点确定同意，点取消拒绝。",

  ["$zishu__buqun1"] = "为了达成目标，力量是必须的。",
  ["$zishu__bugu1"] = "我必须前进，不论有谁阻挡在我面前。",
  ["~zishu__shantao"] = "败者…没有借口…",
}
return extension